<include file="common:__head__"/>
<div class="permissions-tabs">
    <a href="javascript:;" onclick="window.history.back();" style="margin: 18px 0 0 4px;"><img src="./Public/seller/images/permissions6.png"></a>
    <a class="role tabs-bg" href="javascript:;" mark="info">商品管理</a>
    <a class="role" href="javascript:;" mark="images">商品相册</a>
    <a class="role" href="javascript:;" mark="spec">商品规格</a>
</div>
<form class="form-horizontal" id="brand_form" action="{:U('Good/addGood')}" method="post">
<div class="info">
    <div class="permissions-content">
        <div class="permissions-le">
            <div class="add-admin-ipt">
                <span><i>*</i>商品名称:</span>
                <input type="text" name="g_name" id="g_name" placeholder="请填写商品名称" class="w200"/>
            </div>

            <div class="add-admin-ipt">
                <span><i>*</i>商品图片:</span>
                <div class="add-admin-opt">
                    <div class="input-file-show">
                        <span class="show">
                            <a id="img_a" target="_blank" class="nyroModal" rel="gal" href="">
                                <i id="img_i" class="fa fa-picture-o" onmouseover="layer.tips('<img src={$brand.pic}>',this,{tips: [1, '#fff']});" onmouseout="layer.closeAll();"></i>
                            </a>
                        </span>
                        <span class="type-file-box">
                            <input type="text" id="image" name="original_img" value="" class="type-file-text">
                            <input type="hidden" name="thumb" id="thumb" value="">
                            <input type="button" name="button" id="button1" value="选择上传..." class="type-file-button">
                            <input class="type-file-file" onClick="GetUploadify(1,'','good','img_call_back')" size="30" hidefocus="true" nc_type="change_site_logo" title="点击前方预览图可查看大图，点击按钮选择文件并提交表单后上传生效">
                        </span>
                    </div>
                    <span class="err"></span>
                    <p class="notic">品牌图片，最佳显示尺寸为148*28像素</p>
                </div>
            </div>


            <div class="add-admin-ipt">
                <span><i>*</i>商品分类:</span>
                <select name="cat_id" id="cat_id">
                    <option value="0">-- 请选择分类 --</option>
                    <volist name="categories" id="category">
                        <option value="{$category['id']}">{$category['c_name']}</option>
                    </volist>
                </select>
            </div>


            <div class="add-admin-ipt">
                <span><i>*</i>商品品牌:</span>
                <select name="brand_id" id="brand_id">
                    <option value="0">-- 请选择 --</option>
                    <volist name="brands" id="brand">
                        <option value="{$brand['id']}">{$brand['b_name']}</option>
                    </volist>
                </select>
            </div>

            <div class="add-admin-ipt">
                <span><i>*</i>商品简介:</span>
                <textarea name="brief" id="brief" cols="40" rows="3" class="txt-area"></textarea>
            </div>

            <div class="add-admin-ipt">
                <span><i>*</i>商品货号:</span>
                <input type="text" name="good_sn" id="good_sn" placeholder="不填系统自动生成" class="w200"/>
            </div>

            <div class="add-admin-ipt">
                <span><i>*</i>本店售价:</span>
                <input type="text" name="price" id="price" placeholder="请填写商品售价" class="w200" onKeyUp="this.value=this.value.replace(/[^\d.]/g,'')" onpaste="this.value=this.value.replace(/[^\d.]/g,'')"/>
            </div>

            <div class="add-admin-ipt">
                <span><i>*</i>市场价:</span>
                <input type="text" name="market_price" id="market_price" placeholder="请填写市场价" class="w200" onKeyUp="this.value=this.value.replace(/[^\d.]/g,'')" onpaste="this.value=this.value.replace(/[^\d.]/g,'')"/>
            </div>

            <div class="add-admin-ipt">
                <span><i>*</i>销量:</span>
                <input type="text" name="sale_num" id="sale_num" placeholder="请填写销量" class="w200" onKeyUp="this.value=this.value.replace(/[^\d.]/g,'')" onpaste="this.value=this.value.replace(/[^\d.]/g,'')"/>
            </div>

            <div class="add-admin-ipt">
                <span><i>*</i>佣金:</span>
                <input type="text" name="commission" id="commission" placeholder="请填写佣金" class="w200" onKeyUp="this.value=this.value.replace(/[^\d.]/g,'')" onpaste="this.value=this.value.replace(/[^\d.]/g,'')"/>
            </div>

            <div class="add-admin-ipt">
                <span><i>*</i>重量:</span>
                <input type="text" name="weight" id="weight" placeholder="请填写销量" class="w200" onKeyUp="this.value=this.value.replace(/[^\d.]/g,'')" onpaste="this.value=this.value.replace(/[^\d.]/g,'')"/>
            </div>

            <div class="add-admin-ipt">
                <span><i>*</i>库存:</span>
                <input type="text" name="stock" id="stock" placeholder="请填写库存" class="w200" onKeyUp="this.value=this.value.replace(/[^\d.]/g,'')" onpaste="this.value=this.value.replace(/[^\d.]/g,'')"/>
            </div>

            <div class="add-admin-ipt">
                <span><i>*</i>装箱件数:</span>
                <input type="text" name="per_num" id="per_num" placeholder="请填写装箱件数" class="w200" onKeyUp="this.value=this.value.replace(/[^\d.]/g,'')" onpaste="this.value=this.value.replace(/[^\d.]/g,'')"/>
            </div>

            <div class="add-admin-ipt">
                <span><i>*</i>是否可以退款:</span>
                <select name="back_id" id="back_id">
                    <option value="0">是</option>
                    <option value="1">否</option>
                </select>
            </div>

            <div class="add-admin-ipt back_explain" style="display: none;">
                <span><i>*</i>不能退款原因:</span>
                <textarea rows="3" cols="80" name="noback_reason" class="input-txt" id="noback_reason">{$good['noback_reason']}</textarea>
            </div>

            <div class="add-admin-ipt">
                <span><i>*</i>商品详细描述:</span>
                <textarea name="info" id="goods_content" style="float: right;"></textarea>
            </div>

        </div>
        <div class="permissions-ri">
            <a href="" class="permissions-help">帮助和服务</a>
        </div>
    </div>
</div>

<div class="images" style="display: none;">
    <div class="permissions-content">
        <div class="permissions-le">
            <div class="goods_xc" style="width:100px; text-align:center; margin: 5px; display:inline-block;">
                <input type="hidden" name="goods_images[]" value="" class="goods_imgs"/>
                <a href="javascript:void(0);" onClick="GetUploadify(5,'','goods','call_back2');">
                    <img src="__PUBLIC__/images/img_upload.png" width="100" height="100" />
                </a>
            </div>
        </div>
    </div>
</div>

<div class="spec" style="display: none;">
    <div class="permissions-content">
        <div class="permissions-le">
             <dl class="spec_box">
                 <dt class="tit">
                     商品规格&nbsp; <a class="plus_spec" href="javascript:;"><strong>[+]</strong></a>
                 </dt>
                 <dd class="opt">
                     <div class="spec_box">
                         <div style="margin-bottom:10px;" class="spec_k1">
                             <select name="spe_1" class="small form-control spec1 spec_select">
                                 <option value="0" id="default">- 选择规格属性 -</option>
                                 <volist name="spec" id="vo">
                                     <option value="{$vo['id']}">{$vo['s_name']}</option>
                                 </volist>
                             </select>
                             <a class="p_plus" href="javascript:;" for="1"><strong>[+]</strong></a>
                         </div>
                         <div class="alisth1" style="margin-bottom:10px;"></div>
                     </div>
                 </dd>
             </dl>
        </div>
    </div>
</div>


<div style="padding: 0 0 10px 10px;">
    <button class="btn-lg btn-blue" id="submit_btn">保存</button>
</div>
</form>

<script type="text/javascript">


    //退款理由
    $("#back_id").change(function () {
        if($(this).val() == 1){
            $(".back_explain").show();
        }else{
            $(".back_explain").hide();
        }
    });

    //百度编辑器
    var ue = UE.getEditor('goods_content',{
        initialFrameWidth: "100%",
        initialFrameHeight:300,
        autoHeightEnabled: true
    });


    //添加商品规格的值的时候,动态添加input框
    $('body').on('click','.p_plus', function() {
        var l = $(this).attr("for");
        var my_parent = $(this).parent().parent().parent();
        var select_val = my_parent.find('.spec' + l).val();
        if (select_val != 0) {
            var str = '<a>' +
                    '<input type="text" name="spec_' + l + '[]" style="width:80px;" placeholder="规格值">&nbsp;' +
                    '<strong onclick="$(this).parent().remove();" style="margin-right:10px;">[-]</strong>' +
                    '</a>';
            my_parent.find(".spec_box").find('.alisth' + l).append(str);
        }else{
            layer.alert('请先选择规格属性!', {icon: 2});
        }
    });

    //商品规格
    $('.plus_spec').click(function() {
        var spec_i = $('.spec_select').length;
        spec_i += 1;
        $('.p_plus').show();
        var html_str = '<div class="spec_box">' +
                '<div class="spec_k'+ spec_i +'" style="margin-bottom:10px;">' +
                '<select name="spe_'+ spec_i +'" class="small form-control spec'+ spec_i +' spec_select">' +
                '<option value="0" id="default">- 选择规格属性 -</option>' +
                '<volist name="spec" id="vo">' +
                '<option value="{$vo[id]}">{$vo[s_name]}</option>' +
                '</volist>' +
                '</select>' +
                '<a class="p_plus" href="javascript:;" for="'+ spec_i +'"><strong>[+]</strong></a>' +
                '&nbsp;<strong onclick="$(this).parent().parent().remove()">[-]</strong>' +
                '</div>' +
                '<div class="alisth'+ spec_i +'" style="margin-bottom:10px;"></div>' +
                '</div>';
        $(this).parents(".tit").next('.opt').append(html_str);
    });


    //上传商品相册回调函数
    function call_back2(paths){
        var last_div = $(".goods_xc:last").prop("outerHTML");
        for (var i = 0;i<paths.length ;i++ ) {
            $(".goods_xc:eq(0)").before(last_div);	// 插入一个 新图片
            $(".goods_xc:eq(0)").find('a:eq(0)').attr('href',paths[i]).attr('onclick','').attr('target', "_blank");// 修改他的链接地址
            $(".goods_xc:eq(0)").find('img').attr('src',paths[i]);// 修改他的图片路径
            $(".goods_xc:eq(0)").find('a:eq(1)').attr('onclick',"ClearPicArr2(this,'"+paths[i]+"')").text('删除');
            $(".goods_xc:eq(0)").find('input').val(paths[i]); // 设置隐藏域 要提交的值
        }
    }

    //商品图片上传的回调函数
    function img_call_back(fileurl_tmp) {
        $('#thumb').val(fileurl_tmp);
        $("#image").val(fileurl_tmp);
        $("#img_a").attr('href', fileurl_tmp);
        $("#img_i").attr('onmouseover', "layer.tips('<img src="+fileurl_tmp+">',this,{tips: [1, '#fff']});");
    }

    $(function(){

        //tag切换
        $('.permissions-tabs a').click(function() {
            $('.permissions-tabs a').removeClass('tabs-bg');
            $(this).addClass('tabs-bg');
            var mark = $(this).attr('mark');
            $('.images,.spec,.info').hide();
            $('.'+mark).show();
        });


        //添加商品验证
        $("#submit_btn").click(function() {
            //规格类的个数
            var cate = $("#cat_id").val();          // 分类
            var brand = $("#brand_id").val();       // 品牌
            var img = $('#image').val();            // 主图
            var per_num = $("#per_num").val();      // 装箱件数
            var sale_num = $("#sale_num").val();    // 销量
            var commission = $('#commission').val();//佣金
            var stock = $("#stock").val();          // 库存
            var weight = $('#weight').val();        // 重量
            var price = $('#price').val();          // 售价
            var g_name = $('#g_name').val();        // 名称
            var brief = $('#brief').val();          // 简介
            var market_price = $('#market_price').val(); // 市场价
            var goods_imgs = $('.goods_imgs').val(); // 相册
            var noback_reason = $("#noback_reason").val();
            var back_id = $("#back_id").val();
            var goods_content = ue.getContentTxt();


            if(back_id == 1){
                if(noback_reason.length > 20){
                    layer.msg("退款原因超出字数限制！");return false;
                }
            }
            if (g_name == '') {
                layer.msg('请填写商品名称!',{icon:2}); return false;
            }
            if (img == '') {
                layer.msg('请上传商品图片!', {icon: 2,time:1000});return false;
            }
            if (cate == 0) {
                layer.msg('请选择商品分类!',{icon:2});return false;
            }
            if (brand == 0) {
                layer.msg('请选择商品品牌!',{icon:2});return false;
            }
            if (brief == '') {
                layer.msg('请填写商品简介!',{icon:2});return false;
            }
            if (price == '') {
                layer.msg('请正确填写本店售价!',{icon:2});return false;
            }
            if (market_price == '') {
                layer.msg('请正确填写市场价!',{icon:2});return false;
            }

            if (sale_num == '') {
                layer.msg('请正确填写销量!',{icon:2});return false;
            }

            if (commission == '') {
                layer.msg('请正确填写佣金!',{icon:2});return false;
            }

            if (weight == '') {
                layer.msg('请正确填写商品重量!',{icon:2});return false;
            }

            if (stock == '') {
                layer.msg('请正确填写商品库存!',{icon:2});return false;
            }


            if (per_num == '') {
                layer.msg('请正确填写装箱件数!',{icon:2});return false;
            }

            if (goods_content == '') {
                layer.msg('请正确填写商品详细描述!',{icon:2});return false;
            }

            if(!goods_imgs) {
                layer.msg('请上传商品图册!',{icon:2});return false;
            }
            $("#addGoodsForm").submit();
        });


    });
</script>
<include file="common:__foot__"/>